<!DOCTYPE html>
<HTML>
<HEAD>
<TITLE>query layout</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../resources/css/styles.css" rel="stylesheet">
<link href="css/jquery-ui.css" rel="stylesheet">
<link href="../resources/css/datagrid.css" rel="stylesheet">
<script src="http://cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.min.js"></script>
<script src="../resources/component/template.min.js"></script>
<script type="text/javascript" src="../resources/component/jquery.js"></script>
<script type="text/javascript" src="external/jquery-ui.js"></script>
<script type="text/javascript" src="external/jquery.layout-latest.js"></script>
<script type="text/javascript" src="../resources/component/jquery.dataset.js"></script>
<script type="text/javascript" src="external/common.js"></script>
<script type="text/javascript" src="../resources/component/jquery.datagrid.js"></script>
</HEAD>
<BODY>
<form name="metaForm" method="post">
<div style="position: absolute; top: 0; left: 0; right: 0; bottom: 0">
 	<div class="datagrid" id="dtypeGrid" style="height: 95%;">
				<table>
					<thead>
						<tr style="height: 10px;">
							<th>类型编号</th>
							<th>类型名称</th>
							<th>属性名称</th>
							<th>最大长度</th>
							<th>是否可空</th>
							<th>数据精度</th>
							<th>小数位数</th>
						</tr>
					</thead>
					<tbody></tbody>
					<tfoot></tfoot>
				</table>
	</div>
 	<div style="position: absolute;bottom: 0px;">
	 <input type="button" class="btn" value="取得元数据" id="get"/>
		<input type="button" class="btn" value="删除元数据"  id="remove"/>
		<input type="button" class="btn" value="清除元数据"  id="clear" />
	</div>
	</div>
 
</form>
</BODY>
 
<script>
	
	$(function() {
		if(window.parent.sqldefineGrid.getActive()!=null){
			push(window.parent.sqldefineGrid.getActive());
		}
	});
 	var dtypeGriddata = {
		sqlid : "1000",
		pageNo : 1,
		key:"FNAME",
		params : {},
		columns : [ {
			field : "DTYPE",
			cls : "txt-l"
		}, {
			field : "DTYPENAME",
			cls : "txt-l"
		}, {
			field : "FNAME",
			cls : "txt-l" 
		}, {
			field : "MAXLEN",
			cls : "txt-l"
		}, {
			field : "NULLABEL",
			cls : "txt-l"
		}, {
			field : "PRECISION",
			cls : "txt-l"
		} , {
			field : "SCALE",
			cls : "txt-l"
		}  ]
	};
	var dtypeGrid = $("#dtypeGrid").DataGrid(dtypeGriddata);
	$("#get").click(function() {
		var target = window.parent.getMetaBefore();
		var metaSqldefine  = {
				metaSqldefine: target.select_sql,
				sql_options:target.sql_options,
				m:"querymeta",
				s:"JSON"};
			var url = baseURL;
			$.ajax({
	         url: url,
	         type: "GET",
	         dataType: "jsonp",
	         cache: false,
	         data: {
	             allparams: JSON.stringify(metaSqldefine)
	         },
	         success: function(data) {
	           	console.log(data);
	             if (data.outresult === 'success') {
	            	    dtypeGrid.dataset.setDatas(data.datas, [], {
	       				recordcount : data.datas.length
	       			  });
	             	
	             } else if (data.outresult === 'error') {
	                 console.error(data.outdesc);
	                 alert(data.outdesc)
	             }
	         },
	         error: function(data) {
	             console.error(arguments);
	         }
	     });
	});
 
	$("#clear").click(function() {
		dtypeGrid.dataset.setDatas([], [], {
			aggrs : [],
			recordcount : 0
		});
	});
	
	$("#remove").click(function() {
		var records = dtypeGrid.getSeleted();
	    for (var i = 0; i < records.length; i++) {
	    	dtypeGrid.dataset.deleteRecord(records[i]);
	    };  
	});
	
	function push(data){
		if(data){
			dtypeGrid.dataset.setDatas(JSON.parse(data.def_select_metadata), [], {
				recordcount : JSON.parse(data.def_select_metadata).length
			});
		}
	}
	function getParamsJson(){
		var metaJson = {
				def_select_metadata :JSON.stringify(dtypeGrid.dataset.datas)
			};
		return metaJson;
	}
</script>
</HTML>